package net.hn.hnms.biz.support.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import net.hn.hnms.biz.api.feign.model.DataStateVo;
import net.hn.hnms.biz.support.company.domain.dto.ChartDto;
import net.hn.hnms.biz.support.company.domain.vo.ChartVo;
import net.hn.hnms.biz.support.company.domain.vo.ChartXTwoVo;
import net.hn.hnms.biz.support.domain.*;
import net.hn.hnms.biz.support.domain.dto.*;
import net.hn.hnms.biz.support.domain.vo.*;
import net.hn.hnms.biz.support.group.domain.vo.AbscissdataAlarmListVo;
import net.hn.hnms.biz.support.group.domain.vo.AnchordataAlarmListVo;
import net.hn.hnms.biz.support.group.domain.vo.SupportdataAlarmListVo;
import net.hn.hnms.biz.support.mapper.*;
import net.hn.hnms.biz.support.service.RoofService;
import net.hn.hnms.sys.common.core.constant.Constants;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.exception.HuaNengException;
import net.hn.hnms.sys.common.core.utils.StringUtils;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.redis.domain.SysOrganization;
import net.hn.hnms.sys.common.redis.utils.RedisUtils;
import net.hn.hnms.sys.system.api.domain.SysDictData;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @ClassName: RoofServiceImpl
 * @Description 顶板监测实现类
 * @Author 王龙
 * @Date 2022-10-17
 * @Version 0.1
 */
@DS(value = "slave")
@Service
@RequiredArgsConstructor
public class RoofServiceImpl implements RoofService {

    /**
     * 冲击地压阈值配置表Mapper
     */
    @Resource
    private SensorAlarmConfigMapper sensorAlarmConfigMapper;

    /**
     * 顶板离层测点实时Mapper
     */
     //顶板离层
    private final AbscissdataNowMapper abscissdataNowMapper;
    /**
     * 锚杆( 索)测点实时检测Mapper
     */
    @Resource
    private AnchordataNowMapper anchordataNowMapper;
    /**
     * 锚杆( 索)测点历史检测Mapper
     */
    @Resource
    private AnchordataHisMapper anchordataHisMapper;

    /**
     * 锚杆( 索)测点基础信息Mapper
     */
    @Resource
    private AnchorsensorBaseMapper anchorsensorBaseMapper;

    /**
     * 锚杆( 索)测点异常信息Mapper
     */
    @Resource
    private AnchoralarmAbnormalMapper anchoralarmAbnormalMapper;

    /**
     * 顶板离层测点基本信息Mapper
     */
    @Resource
    private AbscisssensorBaseMapper abscisssensorBaseMapper;

    /**
     * 顶板离层测点实时Mapper
     */
    @Resource
    private AbscissdataNowMapper abscissNowMapper;
    /**
     * 顶板离层测点历史Mapper
     */
    @Resource
    private AbscissdataHisMapper abscissHisMapper;
    /**
     * 顶板离层测点异常信息Mapper
     */
    @Resource
    private AbscissalarmAbnormalMapper abscissalarmAbnormalMapper;

    @Resource
    private RoofBaseInfoMapper roofBaseInfoMapper;


    /**
     * 钻孔应力监测异常信息Mapper
     */
    @Resource
    private BoreholealarmAbnormalMapper boreholealarmAbnormalMapper;

    /**
     * 钻孔应力测点历史信息Mapper
     */
    @Resource
    private BoreholedataHisMapper boreholedataHisMapper;

    /**
     * 钻孔应力测点实时信息Mapper
     */
    @Resource
    private BoreholedataNowMapper boreholedataNowMapper;

    /**
     * 钻孔应力测点基本信息Mapper
     */
    @Resource
    private BoreholesensorBaseMapper boreholesensorBaseMapper;

    /**
     * 电磁辐射监测实时信息Mapper
     */
    @Resource
    private EmfdataNowMapper emfdataNowMapper;


    /**
     * 电磁辐射测点基本信息Mapper
     */
    @Resource
    private EmfsensorBaseMapper emfsensorBaseMapper;

    /**
     * 微震监测历史信息Mapper
     */
    @Resource
    private QuakedataHisMapper quakedataHisMapper;


    /**
     * 微震监测实时信息Mapper
     */
    @Resource
    private QuakedataNowMapper quakedataNowMapper;


    /**
     * 微震监测基本信息Mapper
     */
    @Resource
    private QuakesensorBaseMapper quakesensorBaseMapper;

    /**
     * 地音事件历史信息Mapper
     */
    @Resource
    private RocknoisedataHisMapper rocknoisedataHisMapper;

    /**
     * 地音事件实时信息Mapper
     */
    @Resource
    private RocknoisedataNowMapper rocknoisedataNowMapper;


    /**
     * 地音测点基本信息Mapper
     */
    @Resource
    private RocknoisesensorBaseMapper rocknoisesensorBaseMapper;

    /**
     * 支架阻力测点实时信息Mapper
     */
    @Resource
    private SupportdataNowMapper supportdataNowMapper;


    /**
     * 支架阻力测点基础信息表Mapper
     */
    @Resource
    private SupportDataBaseMapper supportDataBaseMapper;

    /**
     * 支架阻力测点历史表Mapper
     */
    @Resource
    private SupportdataHisMapper supportdataHisMapper;

    /**
     * cjdy支架监测NOW表数据
     * @param mineCode
     * @return
     */
    @Override
    public List<SupportdataNowPo> distinctSupportdataNow(String mineCode) {
        List<SupportdataNowPo> supportdataNowPos = supportdataNowMapper.distinctSupportdataNow(mineCode);
        return supportdataNowPos;
    }

    /**
     * 最大离层量  获取实时表的所有数据 离层量= 深基点-浅基点
     * @return
     */
    @Override
    public BigDecimal getAnchordataNowListValue(String mineCode) {

        return abscissdataNowMapper.maxAbscission();
    }

    /**
     * 顶板离层异常数
     * @return
     */
    @Override
    public Integer getRoofSeparationAnomaly() {
        LambdaQueryWrapper<AbscissalarmAbnormalPo> abscissalarmAbnormalPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        Long aLong = abscissalarmAbnormalMapper.selectCount(abscissalarmAbnormalPoLambdaQueryWrapper);
        return aLong.intValue();
    }

    /**
     * 查询顶板离层测点信息数据
     * @return
     */
    @Override
    public Integer getRoofSeparationPoint() {
        LambdaQueryWrapper<AbscissdataNowPo> abscissdataNowPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        Long aLong = abscissdataNowMapper.selectCount(abscissdataNowPoLambdaQueryWrapper);
        return aLong.intValue();
    }

    /**
     * 锚杆异常数
     * @return
     */
    @Override
    public Integer getRockBoltAnomaly() {
        LambdaQueryWrapper<AnchoralarmAbnormalPo> anchoralarmAbnormalPoLambdaQueryWrapper = new LambdaQueryWrapper<>();

        Long aLong = anchoralarmAbnormalMapper.selectCount(anchoralarmAbnormalPoLambdaQueryWrapper);
        return aLong.intValue();
    }

    /**
     * 顶板离层报警曲线
     * @param number
     * @return
     */
    @Override
    public ChartVo riskStatistics(String number) {
        ChartVo chartVo = new ChartVo();
        List<String> xlast = new ArrayList<>();
        List<BigDecimal> ylast = new ArrayList<>();
        List<ChartDto> list = null;
        String day = new String("''");
        //1-周，2-月
        if ("1".equals(number)) {
            day = "'6 day'";
//             list =abscissalarmAbnormalMapper.riskStatisticsWeek();
            list = abscissalarmAbnormalMapper.riskStatistics(day);
        }
        if ("2".equals(number)) {
            day = "'30 day'";
//            list =abscissalarmAbnormalMapper.riskStatisticsMonth();
            list = abscissalarmAbnormalMapper.riskStatistics(day);
        }

        for (ChartDto chartDto : list) {
            xlast.add(new SimpleDateFormat("yyyy-MM-dd").format(chartDto.getTime()));
            ylast.add(chartDto.getValue());
        }
        chartVo.setXData(xlast);
        chartVo.setValeus(ylast);
        return chartVo;
    }

    /**
     * 锚杆测点数
     * @return
     */
    @Override
    public Integer getRockBoltPoint() {
        LambdaQueryWrapper<AnchordataNowPo> anchordataNowPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        Long aLong = anchordataNowMapper.selectCount(anchordataNowPoLambdaQueryWrapper);
        return aLong.intValue();
    }

    /**
     * 钻孔应力异常数
     * @return
     */
    @Override
    public Integer getBoreholeStressAnomaly() {
        LambdaQueryWrapper<BoreholealarmAbnormalPo> boreholealarmAbnormalPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        Long aLong = boreholealarmAbnormalMapper.selectCount(boreholealarmAbnormalPoLambdaQueryWrapper);
        return aLong.intValue();
    }

    /**
     * 钻孔应力测点数
     * @return
     */
    @Override
    public Integer getBoreholeStressPoint() {
//        LambdaQueryWrapper<BoreholedataNowPo> boreholedataNowPoLambdaQueryWrapper = new LambdaQueryWrapper<>();
//        Long aLong = boreholedataNowMapper.selectCount(boreholedataNowPoLambdaQueryWrapper);

//        LambdaQueryWrapper<BoreholesensorBasePo> boreholesensorBasePoLambdaQueryWrapper = new LambdaQueryWrapper<>();

        //base表和now表关联查询,获取钻孔应力测点数
        Integer count = boreholesensorBaseMapper.getBoreholeStressPoint();
        return count;
    }

    /**
     * 地音异常数
     * @return
     */
    @Override
    public Integer getRockNoiseAnomaly() {
        //地音异常数，数据库中暂时不存在Anomaly异常表。
        //TODO 地音暂时 没有判定标准
        return null;
    }

    /**
     * 地音测点数
     * @return
     */
    @Override
    public Integer getRockNoisePoint() {
        //查询base表中的记录数
        LambdaQueryWrapper<RocknoisesensorBasePo> rocknoisesensorBasePoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        Long aLong = rocknoisesensorBaseMapper.selectCount(rocknoisesensorBasePoLambdaQueryWrapper);
        return aLong.intValue();
    }

    /**
     * 微震测点数
     * @return
     */
    @Override
    public Integer getSlightShockPoint() {
        //查询微震base表中的记录数
        LambdaQueryWrapper<QuakesensorBasePo> quakesensorBasePoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        Long aLong = quakesensorBaseMapper.selectCount(quakesensorBasePoLambdaQueryWrapper);
        return aLong.intValue();
    }

    /**
     * 电磁辐射测点数
     * @return
     */
    @Override
    public Integer getElectromagneticRadiationPoint() {
        //查询电磁辐射base的记录数
        LambdaQueryWrapper<EmfsensorBasePo> emfsensorBasePoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        Long aLong = emfsensorBaseMapper.selectCount(emfsensorBasePoLambdaQueryWrapper);

        return aLong.intValue();
    }

    /**
     * 微震次数变化曲线
     * @param number
     * @return
     */
    @Override
    public ChartVo riskStatisticsRockBurstQuake(String number) {
        //判断是周还是月
        ChartVo chartVo = new ChartVo();
        List<String> xlast = new ArrayList<>();
        List<BigDecimal> ylast = new ArrayList<>();
        List<ChartDto> chartDtoList=null;
        String day = new String("''");
        if ("1".equals(number)) {
            //周
             day = "'6 day'";
            chartDtoList= quakedataHisMapper.getriskStatisticsRockBurst(day);
//            chartDtoList= quakedataHisMapper.getriskStatisticsRockBurstWeek();
        } else if ("2".equals(number)) {
            //月
             day ="'30 day'";
//            chartDtoList= quakedataHisMapper.getriskStatisticsRockBurstMonth();
            chartDtoList= quakedataHisMapper.getriskStatisticsRockBurst(day);
        }
        for (ChartDto chartDto : chartDtoList) {
            xlast.add(new SimpleDateFormat("yyyy-MM-dd").format(chartDto.getTime()));
            ylast.add(chartDto.getValue());
        }
        chartVo.setXData(xlast);
        chartVo.setValeus(ylast);

        return chartVo;
    }

    /**
     * 地音能量频次图
     * @param number
     * @return
     */
    @Override
    public ChartXTwoVo riskStatisticsRockBurstBorehole(String number) {
        //判断是周还是月
        ChartXTwoVo chartXTwoVo = new ChartXTwoVo();
        List<String> xlast = new ArrayList<>();
        List<BigDecimal> ylastFrequency = new ArrayList<>();
        List<BigDecimal> ylastEnergy = new ArrayList<>();
        List<ChartDto> chartDtoListFrequency =null;
        List<ChartDto> chartDtoListEnergy =null;
        String day = new String("''");
        if ("1".equals(number)) {
            //周
            day = "'6 day'";
//            chartDtoList= boreholealarmAbnormalMapper.getriskStatisticsRockBurstWeek();
            //钻孔应力异常报警曲线（弃用）
//            chartDtoList= boreholealarmAbnormalMapper.getriskStatisticsRockBurst(day);
            //地音频次曲线
            chartDtoListFrequency= rocknoisedataHisMapper.getriskStatisticsRockBurstFrequency(day);
            //地音能量曲线
            chartDtoListEnergy = rocknoisedataHisMapper.getriskStatisticsRockBurstEnergy(day);
        } else if ("2".equals(number)) {
            //月
            day = "'30 day'";
//            chartDtoList= boreholealarmAbnormalMapper.getriskStatisticsRockBurstMonth();
            //钻孔应力异常报警曲线（弃用）
//            chartDtoList= boreholealarmAbnormalMapper.getriskStatisticsRockBurst(day);
            // //地音频次曲线
            chartDtoListFrequency= rocknoisedataHisMapper.getriskStatisticsRockBurstFrequency(day);
            //地音能量曲线
            chartDtoListEnergy = rocknoisedataHisMapper.getriskStatisticsRockBurstEnergy(day);

        }

//        for (ChartDto chartDto : chartDtoListFrequency) {
//            xlast.add(new SimpleDateFormat("yyyy-MM-dd").format(chartDto.getTime()));
//            ylastFrequency.add(chartDto.getValue());
//            ylastEnergy.add(chartDto.getValue());
//        }
        for (int i = 0; i < chartDtoListFrequency.size(); i++) {
            xlast.add(new SimpleDateFormat("yyyy-MM-dd").format(chartDtoListFrequency.get(i).getTime()));
            //频次
            ylastFrequency.add(chartDtoListFrequency.get(i).getValue());
            //能量
            ylastEnergy.add(chartDtoListEnergy.get(i).getValue());
        }


        //y方向值-频次
        chartXTwoVo.setYValeuFrequency(ylastFrequency);
        //y方向值-能量
        chartXTwoVo.setYValeuEnergy(ylastEnergy);
        //x方向
        chartXTwoVo.setXData(xlast);

        return chartXTwoVo;
    }

    /**
     * 查询顶板报警,顶板数据在now表内，   离层量=深基点-浅基点  (报警条件为离层量>=50mm)
     * @return
     */
    @Override
    public List<AbscissdataNowDto> todayAlarm() {
        List<AbscissdataNowDto> abscissdataNowDtoList=abscissdataNowMapper.getAbscissdataNow();
        if (abscissdataNowDtoList.isEmpty()) {
            return new ArrayList<>();
        }
        return abscissdataNowDtoList;
    }

    /**
     * 钻孔应力报警（查询异常表内的数据）
     * @return
     */
    @Override
    public List<BoreholealarmAbnormalPo> BoreholealarmAbnormalList() {

        //查询今天内的报警数据
        List<BoreholealarmAbnormalPo> boreholealarmAbnormalPoList=boreholealarmAbnormalMapper.BoreholealarmAbnormalList();
        if (boreholealarmAbnormalPoList.isEmpty()) {
            return new ArrayList<>();
        }
        return boreholealarmAbnormalPoList;
    }

    /**
     * cjdy 支架服务
     * @param mineCode
     * @return
     */
    @Override
    public StatisticalInformationCJDYVo cjdyStatisticalInformation(String mineCode) {
        //返回数据的集合
        StatisticalInformationCJDYVo statisticalInformationCJDYVo = new StatisticalInformationCJDYVo();

        //在线测点 获取测点数量(data_time 十分钟以内)
        LambdaQueryWrapper<SupportdataNowPo> queryWrapper = new LambdaQueryWrapper<>();
        //煤矿编码
        queryWrapper.eq(StringUtils.isNotBlank(mineCode), SupportdataNowPo::getMineCode, mineCode);
        //十分钟以内
        Calendar c = Calendar.getInstance();
        Date tenMinutes = new Date();
        c.setTime(tenMinutes);
        c.add(Calendar.MINUTE, -10);
        Date date = c.getTime();
        queryWrapper.ge(SupportdataNowPo::getDataTime, date);
        Long aLong = supportdataNowMapper.selectCount(queryWrapper);
        statisticalInformationCJDYVo.setOnLinePoint(aLong.intValue());

        //最大支架阻力
        //最大阻力位置
        SupportdataNowPo supportdataNowPo = supportdataNowMapper.maxSupportOne(mineCode);
        if (supportdataNowPo == null) {
            statisticalInformationCJDYVo.setMaxHolderLocation("");
            statisticalInformationCJDYVo.setMaxHolderResistance(0F);
        } else {
            statisticalInformationCJDYVo.setMaxHolderLocation(supportdataNowPo.getPointLocation());
            statisticalInformationCJDYVo.setMaxHolderResistance(supportdataNowPo.getPointValue().floatValue());

        }

        //报警测点数
        LambdaQueryWrapper<SupportdataNowPo> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.ge(SupportdataNowPo::getPointValue, 46);
        queryWrapper1.eq(StringUtils.isNotBlank(mineCode), SupportdataNowPo::getMineCode, mineCode);
        Long aLong1 = supportdataNowMapper.selectCount(queryWrapper1);
        statisticalInformationCJDYVo.setPolicePoint(aLong1.intValue());

        return statisticalInformationCJDYVo;
    }

    /**
     * 冲击地压类型:support-支架，abscission-离层，anchor-锚杆所
     * @param type 冲击地压类型:support-支架，abscission-离层，anchor-锚杆所
     * @param mineCode 煤矿编码
     * @return ExtremumVo 在线量 最大值 最小值
     */
    @Override
    public Map<String,Number> extremum(String type, String mineCode) {
        //返回实体ExtremumVo
        Map<String, Number> map = new HashMap<>();
        Long online = 0L;
        //支架
        if ("support".equals(type)) {
            //支架在线测点 获取测点数量(data_time 十分钟以内)
            LambdaQueryWrapper<SupportdataNowPo> queryWrapper = new LambdaQueryWrapper<>();
            //煤矿编码
            queryWrapper.eq(StringUtils.isNotBlank(mineCode), SupportdataNowPo::getMineCode, mineCode);
            //获取过去的日期
            Date date = getPastDate(10);
            queryWrapper.ge(SupportdataNowPo::getDataTime, date);
             online = supportdataNowMapper.selectCount(queryWrapper);
            map.put("online",online);
            //获取支架的最大值
            Float max =supportdataNowMapper.selectOneMax(mineCode);
            map.put("max",max);
            //获取支架的最小值
            Float min =supportdataNowMapper.selectOneMin(mineCode);
            map.put("min",min);
        } else if ("abscission".equals(type)) {
            //离层
            //在线测点 获取测点数量(data_time 十分钟以内)
            LambdaQueryWrapper<AbscissdataNowPo> queryWrapper = new LambdaQueryWrapper<>();
            //煤矿编码
            queryWrapper.eq(StringUtils.isNotBlank(mineCode), AbscissdataNowPo::getMineCode, mineCode);
            //获取过去的日期
            Date date = getPastDate(10);
            queryWrapper.ge(AbscissdataNowPo::getDataTime, date);
            online = abscissNowMapper.selectCount(queryWrapper);
            map.put("online",online);
            //获取深基点的最大值
            Float deepMax =abscissNowMapper.selectOneDeepMax(mineCode);
            map.put("deepMax",deepMax);
            //获取浅基点的最大值
            Float shallowMax =abscissNowMapper.selectOneShallowMax(mineCode);
            map.put("shallowMax",shallowMax);
        } else if ("anchor".equals(type)) {
            //锚杆所
            //在线测点 获取测点数量(data_time 十分钟以内)
            LambdaQueryWrapper<AnchordataNowPo> queryWrapper = new LambdaQueryWrapper<>();
            //煤矿编码
            queryWrapper.eq(StringUtils.isNotBlank(mineCode), AnchordataNowPo::getMineCode, mineCode);
            //获取过去的日期
            Date date = getPastDate(10);
            queryWrapper.ge(AnchordataNowPo::getDataTime, date);
            online = anchordataNowMapper.selectCount(queryWrapper);

            map.put("online",online);
            //判断煤矿编码是不是高头窑
            //高头窑的 锚杆 锚索 需要做特殊处理
            BigDecimal rockBoltMax = new BigDecimal(0);
            BigDecimal anchorCableMax = new BigDecimal(0);
            if ("150621011038".equals(mineCode)) {
                //高头窑   sensor_type  1301=锚杆   1302=锚索
                rockBoltMax = anchordataNowMapper.maxSensorTypeValue("1301");
                anchorCableMax = anchordataNowMapper.maxSensorTypeValue("1302");
            } else {
                //其他煤矿
                 rockBoltMax = anchordataNowMapper.maxValue("锚杆");
                anchorCableMax = anchordataNowMapper.maxValue("锚索");
            }
            //获取锚杆的最大值
            map.put("rockBoltMax",rockBoltMax);
            //获取锚索的最大值
            map.put("anchorCableMax",anchorCableMax);

        }
        return map;
    }

    /**
     * 获取过去N分钟的Date
     * @param minute
     * @return
     */
    @NotNull
    private static Date getPastDate(Integer minute) {
        //十分钟以内
        Calendar c = Calendar.getInstance();
        Date tenMinutes = new Date();
        c.setTime(tenMinutes);
        c.add(Calendar.MINUTE, -minute);
        Date date = c.getTime();
        return date;
    }

    @Override
    public List<DataStateVo> getZjzlMaxTime(String mineCode, String companyCode) {
        QueryWrapper<SupportdataNowPo> wrapper = new QueryWrapper<>();
        wrapper.select("mine_code as minecode, max(create_time) as maxtime")
                .groupBy("mine_code");
        List<Map<String, Object>> maps = supportdataNowMapper.selectMaps(wrapper);
        List<DataStateVo> list=new ArrayList<>();
        maps.forEach(s->{
            DataStateVo vo=new DataStateVo();
            vo.setMaxTime((Date) s.get("maxtime"));
            vo.setMineCode((String) s.get("minecode"));
            list.add(vo);
        });
        return list;
    }

    @Override
    public List<DataStateVo> getDblcMaxTime(String mineCode, String companyCode) {
        QueryWrapper<AbscissdataNowPo> wrapper = new QueryWrapper<>();
        wrapper.select("mine_code as minecode, max(create_time) as maxtime")
                .groupBy("mine_code");
        List<Map<String, Object>> maps = abscissdataNowMapper.selectMaps(wrapper);
        List<DataStateVo> list=new ArrayList<>();
        maps.forEach(s->{
            DataStateVo vo=new DataStateVo();
            vo.setMaxTime((Date) s.get("maxtime"));
            vo.setMineCode((String) s.get("minecode"));
            list.add(vo);
        });
        return list;
    }
    @Override
    public List<DataStateVo> getMgylMaxTime(String mineCode, String companyCode) {
        QueryWrapper<AnchordataNowPo> wrapper = new QueryWrapper<>();
        wrapper.select("mine_code as minecode, max(create_time) as maxtime")
                .groupBy("mine_code");
        List<Map<String, Object>> maps = anchordataNowMapper.selectMaps(wrapper);
        List<DataStateVo> list=new ArrayList<>();
        maps.forEach(s->{
            DataStateVo vo=new DataStateVo();
            vo.setMaxTime((Date) s.get("maxtime"));
            vo.setMineCode((String) s.get("minecode"));
            list.add(vo);
        });
        return list;
    }

    /**
     * 分页条件查询顶板离层实时数据
     * @param pageQuery
     * @param queryNowDto
     * @return
     */
    @Override
    public ResponsePage<AbscissQueryVo> abscissPageNowList(PageQuery pageQuery, QueryNowDto queryNowDto) {

        //分页条件查询顶板离层实时数据
//        List<AbscissQueryVo> abscissQueryVo = abscissNowMapper.abscissPageNowList(abscissQueryDto);
        LambdaQueryWrapper<AbscissdataNowPo> queryWrapper = new LambdaQueryWrapper<>();
        //传感器位置
        queryWrapper.like(StringUtils.isNotBlank(queryNowDto.getPointLocation()),AbscissdataNowPo::getPointLocation, queryNowDto.getPointLocation());
        //传感器状态
        queryWrapper.eq(StringUtils.isNotBlank(queryNowDto.getPointStatus()), AbscissdataNowPo::getPointStatus, queryNowDto.getPointStatus());
        //煤矿编码
        queryWrapper.eq(StringUtils.isNotBlank(queryNowDto.getMineCode()), AbscissdataNowPo::getMineCode, queryNowDto.getMineCode());
        Page<AbscissdataNowPo> abscissdataNowPoPage = abscissNowMapper.selectPage(pageQuery.build(), queryWrapper);
        if (abscissdataNowPoPage.getRecords().isEmpty()) {
            return new ResponsePage<AbscissQueryVo>(new ArrayList(), 0);
        }
        //冲击地压传感器测点状态
        List<SysDictData> sysDictDataList = RedisUtils.getCacheObject(Constants.SYS_DICT_KEY + "cjdy_sensor_status");
        List<AbscissQueryVo> collect = abscissdataNowPoPage.getRecords().stream().map(t -> {
            AbscissQueryVo abscissQueryVo = new AbscissQueryVo();
            //数据时间
            abscissQueryVo.setDataTime(t.getDataTime());
            //创建时间
            abscissQueryVo.setCreateTime(t.getCreateTime());
            //测点编码
            abscissQueryVo.setPointCode(t.getPointCode());
            //传感器位置
            abscissQueryVo.setPointLocation(t.getPointLocation());
            //深基点监测值
            abscissQueryVo.setDeepbasepointValue(t.getDeepbasepointValue());
            //浅基点监测值
            abscissQueryVo.setShallowbasepointValue(t.getShallowbasepointValue());
            //离层量
            abscissQueryVo.setSeparationLayerValue(t.getDeepbasepointValue().subtract(t.getShallowbasepointValue()));
            //测点状态
            if (sysDictDataList.isEmpty()) {
                ////如何字典为空则使用默认
                abscissQueryVo.setPointStatus("0".equals(t.getPointStatus()) ? "正常" : "异常");
            } else {
                sysDictDataList.forEach(k -> {
                            //判断测点状态是否符合字典
                            if (t.getPointStatus().trim().equals(k.getDictValue())) {
                                abscissQueryVo.setPointStatus(k.getDictLabel());
                            }
                        }

                );
            }
            return abscissQueryVo;
        }).collect(Collectors.toList());

        return new ResponsePage<AbscissQueryVo>(collect,abscissdataNowPoPage.getTotal());
    }
    /**
     * 分页条件查询顶板离层历史数据
     * @param pageQuery
     * @param queryHisDto
     * @return
     */
    @Override
    public ResponsePage<AbscissQueryVo> abscissPageHisList(PageQuery pageQuery, QueryHisDto queryHisDto) {

        //分页条件查询顶板离层实时数据
//        List<AbscissQueryVo> abscissQueryVo = abscissNowMapper.abscissPageNowList(abscissQueryDto);
        LambdaQueryWrapper<AbscissdataHisPo> queryWrapper = new LambdaQueryWrapper<>();
        //传感器位置
        queryWrapper.like(StringUtils.isNotBlank(queryHisDto.getPointLocation()),AbscissdataHisPo::getPointLocation, queryHisDto.getPointLocation());
        //传感器状态
        queryWrapper.eq(StringUtils.isNotBlank(queryHisDto.getPointStatus()), AbscissdataHisPo::getPointStatus, queryHisDto.getPointStatus());
        //煤矿编码
        queryWrapper.eq(StringUtils.isNotBlank(queryHisDto.getMineCode()), AbscissdataHisPo::getMineCode, queryHisDto.getMineCode());
        //大于等于开始时间
        queryWrapper.gt(AbscissdataHisPo::getCreateTime, queryHisDto.getStartTime());
        //小于等于结束时间
        queryWrapper.lt(AbscissdataHisPo::getCreateTime, queryHisDto.getEndTime());
        //排序 根据创建时间降序
        queryWrapper.orderByDesc(AbscissdataHisPo::getCreateTime);
        Page<AbscissdataHisPo> abscissdataHisPoPage = abscissHisMapper.selectPage(pageQuery.build(), queryWrapper);
        if (abscissdataHisPoPage.getRecords().isEmpty()) {
            return new ResponsePage<AbscissQueryVo>(new ArrayList(), 0);
        }
        //冲击地压传感器测点状态
        List<SysDictData> sysDictDataList = RedisUtils.getCacheObject(Constants.SYS_DICT_KEY + "cjdy_sensor_status");
        List<AbscissQueryVo> collect = abscissdataHisPoPage.getRecords().stream().map(t -> {
            AbscissQueryVo abscissQueryVo = new AbscissQueryVo();
            //数据时间
            abscissQueryVo.setDataTime(t.getDataTime());
            //创建时间
            abscissQueryVo.setCreateTime(t.getCreateTime());
            //测点编码
            abscissQueryVo.setPointCode(t.getPointCode());
            //传感器位置
            abscissQueryVo.setPointLocation(t.getPointLocation());
            //深基点监测值
            abscissQueryVo.setDeepbasepointValue(t.getDeepbasepointValue());
            //浅基点监测值
            abscissQueryVo.setShallowbasepointValue(t.getShallowbasepointValue());
            //离层量
            abscissQueryVo.setSeparationLayerValue(t.getDeepbasepointValue().subtract(t.getShallowbasepointValue()));
            //测点状态
            if (sysDictDataList.isEmpty()) {
                ////如果字典为空则使用默认
                abscissQueryVo.setPointStatus("0".equals(t.getPointStatus()) ? "正常" : "异常");
            } else {
                sysDictDataList.forEach(k -> {
                            //判断测点状态是否符合字典
                            if (t.getPointStatus().trim().equals(k.getDictValue())) {
                                abscissQueryVo.setPointStatus(k.getDictLabel());
                            }
                        }

                );
            }
            return abscissQueryVo;
        }).collect(Collectors.toList());

        return new ResponsePage<AbscissQueryVo>(collect,abscissdataHisPoPage.getTotal());
    }
    /**
     * 分页条件查询锚杆实时数据
     * @param pageQuery
     * @param queryNowDto
     * @return
     */
    @Override
    public ResponsePage<AnchorQueryVo> anchorPageNowList(PageQuery pageQuery, QueryNowDto queryNowDto) {
        LambdaQueryWrapper<AnchordataNowPo> queryWrapper = new LambdaQueryWrapper<>();
        //传感器位置
        queryWrapper.like(StringUtils.isNotBlank(queryNowDto.getPointLocation()),AnchordataNowPo::getPointLocation, queryNowDto.getPointLocation());
        //传感器状态
        queryWrapper.eq(StringUtils.isNotBlank(queryNowDto.getPointStatus()), AnchordataNowPo::getPointStatus, queryNowDto.getPointStatus());
        //煤矿编码
        queryWrapper.eq(StringUtils.isNotBlank(queryNowDto.getMineCode()), AnchordataNowPo::getMineCode, queryNowDto.getMineCode());
        Page<AnchordataNowPo> anchordataNowPoPage = anchordataNowMapper.selectPage(pageQuery.build(), queryWrapper);
        if (anchordataNowPoPage.getRecords().isEmpty()) {
            return new ResponsePage<AnchorQueryVo>(new ArrayList(), 0);
        }
        //冲击地压传感器测点状态
        List<SysDictData> sysDictDataList = RedisUtils.getCacheObject(Constants.SYS_DICT_KEY + "cjdy_sensor_status");
        List<AnchorQueryVo> collect = anchordataNowPoPage.getRecords().stream().map(t -> {
            AnchorQueryVo anchorQueryVo = new AnchorQueryVo();
            //数据时间
            anchorQueryVo.setDataTime(t.getDataTime());
            //创建时间
            anchorQueryVo.setCreateTime(t.getCreateTime());
            //测点编码
            anchorQueryVo.setPointCode(t.getPointCode());
            //传感器位置
            anchorQueryVo.setPointLocation(t.getPointLocation());
            //数据值
            anchorQueryVo.setPointValue(t.getPointValue());
            //锚杆（索）破断值
            AnchorsensorBasePo anchorsensorBasePo = anchorsensorBaseMapper.selectOne(new LambdaQueryWrapper<AnchorsensorBasePo>().eq(AnchorsensorBasePo::getPointCode, t.getPointCode()));
            anchorQueryVo.setAnchorBreakingValue(anchorsensorBasePo==null?null:anchorsensorBasePo.getAnchorBreakingValue());

            //测点状态
            if (sysDictDataList.isEmpty()) {
                //如果字典为空则使用默认
                anchorQueryVo.setPointStatus("0".equals(t.getPointStatus()) ? "正常" : "异常");
            } else {
                sysDictDataList.forEach(k -> {
                            //判断测点状态是否符合字典
                            if (t.getPointStatus().trim().equals(k.getDictValue())) {
                                anchorQueryVo.setPointStatus(k.getDictLabel());
                            }
                        }

                );
            }
            return anchorQueryVo;
        }).collect(Collectors.toList());
        return new ResponsePage<AnchorQueryVo>(collect,anchordataNowPoPage.getTotal());
    }



    /**
     * 分页条件查询锚杆索历史数据
     * @param pageQuery
     * @param queryHisDto
     * @return
     */
    @Override
    public ResponsePage<AnchorQueryVo> anchorPageHisList(PageQuery pageQuery, QueryHisDto queryHisDto) {
        LambdaQueryWrapper<AnchordataHisPo> queryWrapper = new LambdaQueryWrapper<>();
        //传感器位置
        queryWrapper.like(StringUtils.isNotBlank(queryHisDto.getPointLocation()),AnchordataHisPo::getPointLocation, queryHisDto.getPointLocation());
        //传感器状态
        queryWrapper.eq(StringUtils.isNotBlank(queryHisDto.getPointStatus()), AnchordataHisPo::getPointStatus, queryHisDto.getPointStatus());
        //煤矿编码
        queryWrapper.eq(StringUtils.isNotBlank(queryHisDto.getMineCode()), AnchordataHisPo::getMineCode, queryHisDto.getMineCode());
        //大于等于开始时间
        queryWrapper.gt(AnchordataHisPo::getCreateTime, queryHisDto.getStartTime());
        //小于等于结束时间
        queryWrapper.lt(AnchordataHisPo::getCreateTime, queryHisDto.getEndTime());
        //排序 根据创建时间降序
        queryWrapper.orderByDesc(AnchordataHisPo::getCreateTime);
        Page<AnchordataHisPo> anchordataHisPoPage = anchordataHisMapper.selectPage(pageQuery.build(), queryWrapper);
        if (anchordataHisPoPage.getRecords().isEmpty()) {
            return new ResponsePage<AnchorQueryVo>(new ArrayList(), 0);
        }
        //冲击地压传感器测点状态
        List<SysDictData> sysDictDataList = RedisUtils.getCacheObject(Constants.SYS_DICT_KEY + "cjdy_sensor_status");
        List<AnchorQueryVo> collect = anchordataHisPoPage.getRecords().stream().map(t -> {
            AnchorQueryVo anchorQueryVo = new AnchorQueryVo();
            //数据时间
            anchorQueryVo.setDataTime(t.getDataTime());
            //创建时间
            anchorQueryVo.setCreateTime(t.getCreateTime());
            //测点编码
            anchorQueryVo.setPointCode(t.getPointCode());
            //传感器位置
            anchorQueryVo.setPointLocation(t.getPointLocation());
            //数据值
            anchorQueryVo.setPointValue(t.getPointValue());
            //锚杆（索）破断值
            AnchorsensorBasePo anchorsensorBasePo = anchorsensorBaseMapper.selectOne(new LambdaQueryWrapper<AnchorsensorBasePo>().eq(AnchorsensorBasePo::getPointCode, t.getPointCode()));
            anchorQueryVo.setAnchorBreakingValue(anchorsensorBasePo==null?null:anchorsensorBasePo.getAnchorBreakingValue());
            //测点状态
            if (sysDictDataList.isEmpty()) {
                //如果字典为空则使用默认
                anchorQueryVo.setPointStatus("0".equals(t.getPointStatus()) ? "正常" : "异常");
            } else {
                sysDictDataList.forEach(k -> {
                            //判断测点状态是否符合字典
                            if (t.getPointStatus().trim().equals(k.getDictValue())) {
                                anchorQueryVo.setPointStatus(k.getDictLabel());
                            }
                        }

                );
            }
            return anchorQueryVo;
        }).collect(Collectors.toList());
        return new ResponsePage<AnchorQueryVo>(collect,anchordataHisPoPage.getTotal());
    }

    /**
     * 条件查询顶板离层历史数据测点曲线
     * @param pointDto
     * @return
     */
    @Override
    public ChartDateVo abscissPointHistoryCurve(PointDto pointDto) {
        LambdaQueryWrapper<AbscissdataHisPo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //测点编码
        lambdaQueryWrapper.eq(AbscissdataHisPo::getPointCode, pointDto.getPointCode());
        //查询大于等于开始时间
        lambdaQueryWrapper.ge(AbscissdataHisPo::getCreateTime, pointDto.getStartTime());
        //小于等于结束时间
        lambdaQueryWrapper.le(AbscissdataHisPo::getCreateTime, pointDto.getEndTime());
        //根据降序时间进行排序
        lambdaQueryWrapper.orderByDesc(AbscissdataHisPo::getCreateTime);
        List<AbscissdataHisPo> abscissdataHisPos = abscissHisMapper.selectList(lambdaQueryWrapper);
        if (abscissdataHisPos.isEmpty()) {
            return new ChartDateVo(new ArrayList<>(), new ArrayList<>());
        }
        //返回数据实体Vo
        ChartDateVo chartDateVo = new ChartDateVo();
        //返回日期集合
        List<Date> dates = new ArrayList<>();
        //返回数值集合
        List<BigDecimal> values = new ArrayList<>();
        abscissdataHisPos.forEach(t->{
            //日期
            dates.add(t.getDataTime());
            //深基点-浅基点=离层里
            values.add(t.getDeepbasepointValue().subtract(t.getShallowbasepointValue()));
        });

        chartDateVo.setDate(dates);
        chartDateVo.setValue(values);
        return chartDateVo;
    }

    /**
     * 条件查询顶板离层历史数据测点列表
     * @param pointDto
     * @return
     */
    @Override
    public List<AbscissPointHistoryListVo> abscissPointHistoryList(PointDto pointDto) {
        LambdaQueryWrapper<AbscissdataHisPo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //测点编码
        lambdaQueryWrapper.eq(AbscissdataHisPo::getPointCode, pointDto.getPointCode());
        //查询大于等于开始时间
        lambdaQueryWrapper.ge(AbscissdataHisPo::getCreateTime, pointDto.getStartTime());
        //小于等于结束时间
        lambdaQueryWrapper.le(AbscissdataHisPo::getCreateTime, pointDto.getEndTime());
        //根据降序时间进行排序
        lambdaQueryWrapper.orderByDesc(AbscissdataHisPo::getCreateTime);
        List<AbscissdataHisPo> abscissdataHisPos = abscissHisMapper.selectList(lambdaQueryWrapper);
        if (abscissdataHisPos.isEmpty()) {
            return new ArrayList<>();
        }

        //冲击地压传感器测点状态
        List<SysDictData> sysDictDataList = RedisUtils.getCacheObject(Constants.SYS_DICT_KEY + "cjdy_sensor_status");

        //返回数据集合
        List<AbscissPointHistoryListVo> collect = abscissdataHisPos.stream().map(t -> {
            AbscissPointHistoryListVo abscissPointHistoryListVo = new AbscissPointHistoryListVo();
            //日期
            abscissPointHistoryListVo.setDate(t.getDataTime());
            //创建时间
            abscissPointHistoryListVo.setCreateDate(t.getCreateTime());
            //深基点
            abscissPointHistoryListVo.setDeepbasepointValue(t.getDeepbasepointValue());
            //浅基点
            abscissPointHistoryListVo.setShallowbasepointValue(t.getShallowbasepointValue());
            //离层量
            abscissPointHistoryListVo.setValue(t.getDeepbasepointValue().subtract(t.getShallowbasepointValue()));
            //状态
            abscissPointHistoryListVo.setStateCode(t.getPointStatus());
            //测点状态
            if (sysDictDataList.isEmpty()) {
                ////如何字典为空则使用默认
                abscissPointHistoryListVo.setState("0".equals(t.getPointStatus()) ? "正常" : "异常");
            } else {
                sysDictDataList.forEach(k -> {
                            //判断测点状态是否符合字典
                            if (t.getPointStatus().trim().equals(k.getDictValue())) {
                                abscissPointHistoryListVo.setState(k.getDictLabel());
                            }
                        }

                );
            }

            return abscissPointHistoryListVo;
        }).collect(Collectors.toList());
        return collect;
    }

    /**
     * 条件查询锚杆索历史数据测点曲线
     * @param pointDto
     * @return
     */
    @Override
    public ChartDateVo anchorPointHistoryCurve(PointDto pointDto) {
        LambdaQueryWrapper<AnchordataHisPo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //测点编码
        lambdaQueryWrapper.eq(AnchordataHisPo::getPointCode, pointDto.getPointCode());
        //查询大于等于开始时间
        lambdaQueryWrapper.ge(AnchordataHisPo::getCreateTime, pointDto.getStartTime());
        //小于等于结束时间
        lambdaQueryWrapper.le(AnchordataHisPo::getCreateTime, pointDto.getEndTime());
        //根据降序时间进行排序
        lambdaQueryWrapper.orderByDesc(AnchordataHisPo::getCreateTime);
        List<AnchordataHisPo> anchordataHisPos = anchordataHisMapper.selectList(lambdaQueryWrapper);
        if (anchordataHisPos.isEmpty()) {
            return new ChartDateVo(new ArrayList<>(), new ArrayList<>());
        }
        //返回数据实体Vo
        ChartDateVo chartDateVo = new ChartDateVo();
        //返回日期集合
        List<Date> dates = new ArrayList<>();
        //返回数值集合
        List<BigDecimal> values = new ArrayList<>();
        anchordataHisPos.forEach(t->{
            //日期
            dates.add(t.getDataTime());
            //测点值
            values.add(t.getPointValue());
        });

        chartDateVo.setDate(dates);
        chartDateVo.setValue(values);
        return chartDateVo;
    }

    /**
     * 条件查询锚杆索历史数据测点列表
     * @param pointDto
     * @return
     */
    @Override
    public List<AnchorPointHistoryListVo> anchorPointHistoryList(PointDto pointDto) {
        LambdaQueryWrapper<AnchordataHisPo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        //测点编码
        lambdaQueryWrapper.eq(AnchordataHisPo::getPointCode, pointDto.getPointCode());
        //查询大于等于开始时间
        lambdaQueryWrapper.ge(AnchordataHisPo::getCreateTime, pointDto.getStartTime());
        //小于等于结束时间
        lambdaQueryWrapper.le(AnchordataHisPo::getCreateTime, pointDto.getEndTime());
        //根据降序时间进行排序
        lambdaQueryWrapper.orderByDesc(AnchordataHisPo::getCreateTime);
        List<AnchordataHisPo> anchordataHisPos = anchordataHisMapper.selectList(lambdaQueryWrapper);
        if (anchordataHisPos.isEmpty()) {
            return new ArrayList<>();
        }

        //冲击地压传感器测点状态
        List<SysDictData> sysDictDataList = RedisUtils.getCacheObject(Constants.SYS_DICT_KEY + "cjdy_sensor_status");

        //返回数据集合
        List<AnchorPointHistoryListVo> collect = anchordataHisPos.stream().map(t -> {
            AnchorPointHistoryListVo anchorPointHistoryListVo = new AnchorPointHistoryListVo();
            //日期
            anchorPointHistoryListVo.setDate(t.getDataTime());
            //创建时间
            anchorPointHistoryListVo.setCreateDate(t.getCreateTime());
            //测点值
            anchorPointHistoryListVo.setValue(t.getPointValue());
            //状态
            anchorPointHistoryListVo.setStateCode(t.getPointStatus());
            //测点状态
            if (sysDictDataList.isEmpty()) {
                ////如何字典为空则使用默认
                anchorPointHistoryListVo.setState("0".equals(t.getPointStatus()) ? "正常" : "异常");
            } else {
                sysDictDataList.forEach(k -> {
                            //判断测点状态是否符合字典
                            if (t.getPointStatus().trim().equals(k.getDictValue())) {
                                anchorPointHistoryListVo.setState(k.getDictLabel());
                            }
                        }

                );
            }

            return anchorPointHistoryListVo;
        }).collect(Collectors.toList());
        return collect;
    }

    /**
     * 获取矿压监测（锚杆所.顶板.支架）BaseSensorTable表所有信息
     * @return
     */
    @Override
    public List<BaseSensorCoordDto> getKyjcBaseSensorTableAllList(String mineCode) {
        List<BaseSensorCoordDto> baseSensorCoordDtoList = new ArrayList<>();
        //获取顶板离层的base数据
        LambdaQueryWrapper<AbscisssensorBasePo> abscisssensorBasePoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        abscisssensorBasePoLambdaQueryWrapper.eq(StringUtils.isNotBlank(mineCode), AbscisssensorBasePo::getMineCode, mineCode);
        List<AbscisssensorBasePo> abscisssensorBasePos = abscisssensorBaseMapper.selectList(abscisssensorBasePoLambdaQueryWrapper);
        if (!abscisssensorBasePos.isEmpty()) {
            abscisssensorBasePos.stream().forEach(abscisssensorBasePo -> {
                BaseSensorCoordDto baseSensorCoordDto = new BaseSensorCoordDto();
                //传感器编码 分站编码
                baseSensorCoordDto.setPointCode(abscisssensorBasePo.getPointCode());
                //传感器名称 分站名称
                baseSensorCoordDto.setLocation(abscisssensorBasePo.getPointLocation());
                //传感器类型编码
                baseSensorCoordDto.setSensorTypeCode(abscisssensorBasePo.getSensorType());
                //传感器类型名称
                baseSensorCoordDto.setSensorTypeName("顶板离层位移");
                //x
                baseSensorCoordDto.setXCoordinate(abscisssensorBasePo.getXCoordinate());
                //y
                baseSensorCoordDto.setYCoordinate(abscisssensorBasePo.getYCoordinate());
                //z
                baseSensorCoordDto.setZCoordinate(abscisssensorBasePo.getZCoordinate());

                baseSensorCoordDtoList.add(baseSensorCoordDto);
            });
        }

        //获取锚杆所的Base数据
        LambdaQueryWrapper<AnchorsensorBasePo> anchorsensorBasePoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        anchorsensorBasePoLambdaQueryWrapper.eq(StringUtils.isNotBlank(mineCode), AnchorsensorBasePo::getMineCode, mineCode);
        List<AnchorsensorBasePo> anchorsensorBasePos = anchorsensorBaseMapper.selectList(anchorsensorBasePoLambdaQueryWrapper);
        if (!anchorsensorBasePos.isEmpty()) {
            anchorsensorBasePos.stream().forEach(anchorsensorBasePo -> {
                BaseSensorCoordDto baseSensorCoordDto = new BaseSensorCoordDto();
                //传感器编码 分站编码
                baseSensorCoordDto.setPointCode(anchorsensorBasePo.getPointCode());
                //传感器名称 分站名称
                baseSensorCoordDto.setLocation(anchorsensorBasePo.getPointLocation());
                //传感器类型编码
                baseSensorCoordDto.setSensorTypeCode(anchorsensorBasePo.getSensorType());
                //传感器类型名称
                //1301是锚杆
                //1302是锚索
                if ("1301".equals(anchorsensorBasePo.getSensorType())) {
                    baseSensorCoordDto.setSensorTypeName("锚杆");
                } else if ("1302".equals(anchorsensorBasePo.getSensorType())) {
                    baseSensorCoordDto.setSensorTypeName("锚索");

                } else {
                    baseSensorCoordDto.setSensorTypeName("传感器类型错误，无法区分锚杆所");
                }
                //x
                baseSensorCoordDto.setXCoordinate(new BigDecimal(anchorsensorBasePo.getXCoordinate()));
                //y
                baseSensorCoordDto.setYCoordinate(new BigDecimal(anchorsensorBasePo.getYCoordinate()));
                //z
                baseSensorCoordDto.setZCoordinate(new BigDecimal(anchorsensorBasePo.getZCoordinate()));

                baseSensorCoordDtoList.add(baseSensorCoordDto);
            });
        }
        //获取支架的base数据
        LambdaQueryWrapper<SupportDataBasePo> supportDataBasePoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        supportDataBasePoLambdaQueryWrapper.eq(StringUtils.isNotBlank(mineCode), SupportDataBasePo::getMineCode, mineCode);
        List<SupportDataBasePo> supportDataBasePos = supportDataBaseMapper.selectList(supportDataBasePoLambdaQueryWrapper);
        if (!supportDataBasePos.isEmpty()) {
            supportDataBasePos.stream().forEach(supportDataBasePo -> {
                BaseSensorCoordDto baseSensorCoordDto = new BaseSensorCoordDto();
                //传感器编码 分站编码
                baseSensorCoordDto.setPointCode(supportDataBasePo.getPointCode());
                //传感器名称 分站名称
                baseSensorCoordDto.setLocation(supportDataBasePo.getPointLocation());
                //传感器类型编码
                baseSensorCoordDto.setSensorTypeCode(supportDataBasePo.getSensorType());
                //传感器类型名称
                baseSensorCoordDto.setSensorTypeName("支架阻力");
                //x
                baseSensorCoordDto.setXCoordinate(supportDataBasePo.getXCoordinate());
                //y
                baseSensorCoordDto.setYCoordinate(supportDataBasePo.getYCoordinate());
                //z
                baseSensorCoordDto.setZCoordinate(supportDataBasePo.getZCoordinate());

                baseSensorCoordDtoList.add(baseSensorCoordDto);
            });
        }
        return baseSensorCoordDtoList;
    }

    /**
     * 获取冲击地压钻孔应力BaseSensorTable表所有信息
     * @return
     */
    @Override
    public List<BaseSensorCoordDto> getZkylBaseSensorTableAllList(String mineCode) {
        LambdaQueryWrapper<BoreholesensorBasePo> boreholesensorBasePoLambdaQueryWrapper = new LambdaQueryWrapper<>();
        boreholesensorBasePoLambdaQueryWrapper.eq(StringUtils.isNotBlank(mineCode), BoreholesensorBasePo::getMineCode, mineCode);
        List<BoreholesensorBasePo> boreholesensorBasePos = boreholesensorBaseMapper.selectList(boreholesensorBasePoLambdaQueryWrapper);
        if (boreholesensorBasePos.isEmpty()) {
            return new ArrayList<>();
        }
        return boreholesensorBasePos.stream().map(t -> {
            BaseSensorCoordDto baseSensorCoordDto = new BaseSensorCoordDto();
            //传感器编码 分站编码
            baseSensorCoordDto.setPointCode(t.getPointCode());
            //传感器名称 分站名称
            baseSensorCoordDto.setLocation(t.getMonitorAreaName()+t.getPointLocation());
            //传感器类型编码
            baseSensorCoordDto.setSensorTypeCode(t.getSensorType());
            //传感器类型名称
            baseSensorCoordDto.setSensorTypeName("钻孔应力");
            //x
            baseSensorCoordDto.setXCoordinate(t.getXCoordinate());
            //y
            baseSensorCoordDto.setYCoordinate(t.getYCoordinate());
            //z
            baseSensorCoordDto.setZCoordinate(t.getZCoordinate());

            return baseSensorCoordDto;

        }).collect(Collectors.toList());

    }

    /**
     * 获取顶板离层报警列表
     * @param mineCode
     * @return
     */
    @Override
    public List<AbscissdataAlarmListVo> getAbscissAlarmList(String mineCode) {
        //获取冲击地压阈值配置表
        //1101	支架阈值
        //1401	顶板离层阈值
        //1301	锚杆阈值
        //1302	锚索阈值
        SensorAlarmConfigPo oneInfo = sensorAlarmConfigMapper.getOneInfo(mineCode, "1401");
        if (oneInfo == null || oneInfo.getThresholdValue() == null) {
            //查询不到阈值信息
            return new ArrayList<>();
        }
        //获取煤矿信息
        //获取当前公司的所有煤矿
        SysOrganization sysOrganization = RedisUtils.getCacheObject(Constants.SYS_CODE_KEY + mineCode);
        if (sysOrganization == null) {
            throw new HuaNengException(Constants.FAIL, "煤矿编码出错，请检查词典" + mineCode);

        }
        //查询顶板离层历史表 获取今日的报警数据
//        List<AbscissdataHisPo> sensorAlarmPos = abscissHisMapper.getTodayAlarmListByValue(mineCode,oneInfo.getThresholdValue());

        //查询实时表内的报警数据 获取今日报警数据
        List<AbscissdataNowPo> sensorAlarmPos = abscissNowMapper.getTodayAlarmListByValue(mineCode,oneInfo.getThresholdValue());
        if (sensorAlarmPos.isEmpty()) {
            return new ArrayList<>();
        }
        return sensorAlarmPos.stream().map(t -> {
            AbscissdataAlarmListVo abscissdataAlarmListVo = new AbscissdataAlarmListVo();
            abscissdataAlarmListVo.setPointCode(t.getPointCode());
            abscissdataAlarmListVo.setMineCode(t.getMineCode());
            abscissdataAlarmListVo.setMineName(sysOrganization.getOrgName());
            abscissdataAlarmListVo.setPointLocation(t.getPointLocation());
            abscissdataAlarmListVo.setDeepbasepointValue(t.getDeepbasepointValue());
            abscissdataAlarmListVo.setShallowbasepointValue(t.getShallowbasepointValue());
            abscissdataAlarmListVo.setThresholdValue(oneInfo.getThresholdValue());
            abscissdataAlarmListVo.setDateTime(t.getDataTime());
            return abscissdataAlarmListVo;
        }).collect(Collectors.toList());
    }

    /**
     * 获取今日锚杆索报警列表
     * @param mineCode
     * @return
     */
    @Override
    public List<AnchordataAlarmListVo> getTodayAnchordataAlarmList(String mineCode) {
        //获取冲击地压阈值配置表
        //1101	支架阈值
        //1401	顶板离层阈值
        //1301	锚杆阈值
        //1302	锚索阈值

        //获取当前公司的所有煤矿
        SysOrganization sysOrganization = RedisUtils.getCacheObject(Constants.SYS_CODE_KEY + mineCode);
        if (sysOrganization == null) {
            throw new HuaNengException(Constants.FAIL, "煤矿编码出错，请检查词典" + mineCode);

        }

        //煤矿锚杆所历史表报警列表集合
//        List<AnchordataHisPo> voList = new ArrayList<>();

        //煤矿锚杆所实时表报警列表集合
        List<AnchordataNowPo> voList = new ArrayList<>();
        //获取锚杆阈值
        SensorAlarmConfigPo oneInfoPole = sensorAlarmConfigMapper.getOneInfo(mineCode, "1301");
        if (oneInfoPole == null || oneInfoPole.getThresholdValue() == null) {
            //查询不到阈值信息
//            return new ArrayList<>();
        } else {
            //有阈值 查询锚杆历史表今日所有报警列表
//            List<AnchordataHisPo> sensorAlarmPos = anchordataHisMapper.getTodayAlarmListByValue(mineCode,oneInfoPole.getThresholdValue(),oneInfoPole.getSensorTypeCode());

            //有阈值 查询锚杆实时表今日所有报警列表
            List<AnchordataNowPo> sensorAlarmPos = anchordataNowMapper.getTodayAlarmListByValue(mineCode,oneInfoPole.getThresholdValue(),oneInfoPole.getSensorTypeCode());
            sensorAlarmPos.forEach(t->{
                voList.add(t);
            });

        }
        //获取锚索阈值
        SensorAlarmConfigPo oneInfoCable = sensorAlarmConfigMapper.getOneInfo(mineCode, "1302");
        if (oneInfoCable == null || oneInfoCable.getThresholdValue() == null) {
            //查询不到阈值信息
//            return new ArrayList<>();
        }else {
            //查询锚索历史表 获取今日的报警数据
//            List<AnchordataHisPo> sensorAlarmPos = anchordataHisMapper.getTodayAlarmListByValue(mineCode,oneInfoCable.getThresholdValue(),oneInfoCable.getSensorTypeCode());
            //查询锚索实时表 获取今日的报警数据

            List<AnchordataNowPo> sensorAlarmPos = anchordataNowMapper.getTodayAlarmListByValue(mineCode,oneInfoCable.getThresholdValue(),oneInfoCable.getSensorTypeCode());
            sensorAlarmPos.forEach(t->{
                voList.add(t);
            });
        }
        //返回封装集合
        return voList.stream().map(t -> {
            AnchordataAlarmListVo anchordataAlarmListVo = new AnchordataAlarmListVo();
            //测点编码
            anchordataAlarmListVo.setPointCode(t.getPointCode());
            //煤矿
            anchordataAlarmListVo.setMineCode(t.getMineCode());
            anchordataAlarmListVo.setMineName(sysOrganization.getOrgName());
            //传感器位置
            anchordataAlarmListVo.setPointLocation(t.getPointLocation());
            //传感器类型
//            anchordataAlarmListVo.setAlarmType(t.getSensorType());

            //监测值
            anchordataAlarmListVo.setValue(t.getPointValue());
            //阈值
            if (oneInfoPole.getSensorTypeCode().equals(t.getSensorType())) {
                //锚杆类型相同
                anchordataAlarmListVo.setThresholdValue(oneInfoPole.getThresholdValue());
                anchordataAlarmListVo.setAlarmType(oneInfoPole.getSensorTypeName());
            } else if (oneInfoCable.getSensorTypeCode().equals(t.getSensorType())) {
                //锚索类型相同
                anchordataAlarmListVo.setThresholdValue(oneInfoCable.getThresholdValue());
                anchordataAlarmListVo.setAlarmType(oneInfoCable.getSensorTypeName());
            } else {
                anchordataAlarmListVo.setThresholdValue(null);
            }
            //数据时间
            anchordataAlarmListVo.setDateTime(t.getDataTime());
            return anchordataAlarmListVo;
        }).collect(Collectors.toList());
    }

    /**
     * 获取今日支架报警列表
     * @param mineCode
     * @return
     */
    @Override
    public List<SupportdataAlarmListVo> getTodaySupportdataAlarmList(String mineCode) {
        //获取冲击地压阈值配置表
        //1101	支架阈值
        //1401	顶板离层阈值
        //1301	锚杆阈值
        //1302	锚索阈值

        //获取当前公司的所有煤矿
        SysOrganization sysOrganization = RedisUtils.getCacheObject(Constants.SYS_CODE_KEY + mineCode);
        if (sysOrganization == null) {
            throw new HuaNengException(Constants.FAIL, "煤矿编码出错，请检查词典" + mineCode);

        }
        //获取支架阈值
        SensorAlarmConfigPo oneInfo = sensorAlarmConfigMapper.getOneInfo(mineCode, "1101");
        if (oneInfo == null || oneInfo.getThresholdValue() == null) {
            return new ArrayList<>();
        }
        //历史表 获取今日支架报警列表
//        List<SupportdataHisPo> supportdataList = supportdataHisMapper.getTodaySupportdataAlarmList(mineCode, oneInfo.getThresholdValue());

        //实时表 获取今日支架报警列表
        List<SupportdataNowPo> supportdataList = supportdataNowMapper.getTodaySupportdataAlarmList(mineCode, oneInfo.getThresholdValue());
        if (supportdataList.isEmpty()) {
            return new ArrayList<>();
        }
        return supportdataList.stream().map(t -> {
            SupportdataAlarmListVo supportdataAlarmListVo = new SupportdataAlarmListVo();
            //测点编码
            supportdataAlarmListVo.setPointCode(t.getPointCode());
            //煤矿
            supportdataAlarmListVo.setMineCode(t.getMineCode());
            supportdataAlarmListVo.setMineName(sysOrganization.getOrgName());
            //传感器位置
            supportdataAlarmListVo.setPointLocation(t.getPointLocation());
            //监测值
            supportdataAlarmListVo.setValue(t.getPointValue());
            //阈值
            supportdataAlarmListVo.setThresholdValue(oneInfo.getThresholdValue());
            //数据时间
            supportdataAlarmListVo.setDateTime(t.getDataTime());
            return supportdataAlarmListVo;
        }).collect(Collectors.toList());
    }

    /**
     * 根据类型获取设备超限阈值
     * @param type
     * @param mineCode
     * @return
     */
    @Override
    public SensorAlarmConfigPo exceedsThresholdByType(String type, String mineCode) {
        SensorAlarmConfigPo sensorAlarmConfigPo = sensorAlarmConfigMapper.selectOne(new LambdaQueryWrapper<SensorAlarmConfigPo>().
                eq(StringUtils.isNotBlank(mineCode), SensorAlarmConfigPo::getMineCode, mineCode)
                .eq(SensorAlarmConfigPo::getSensorTypeCode, type));
        if (sensorAlarmConfigPo!= null) {
            return sensorAlarmConfigPo;
        }
        return new SensorAlarmConfigPo();
    }

    @Override
    public RoofBaseInfoVo getRoofBaseInfo(String mineCode) {
        return roofBaseInfoMapper.getRoofBaseInfo(mineCode);
    }

}
